//
//  DetailTableViewCell.m
//  滴滴快拍
//
//  Created by dllo on 16/5/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "DetailTableViewCell.h"
#import <AVFoundation/AVFoundation.h>
#import "UIImageView+WebCache.h"
#import <Masonry/Masonry.h>


@implementation DetailTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;

}

- (void)createView {
  
    
    self.picImageView = [[BaseImageView alloc] init];
    [self.contentView addSubview:self.picImageView];
    
    
//    self.backView = [[BaseView alloc] init];
//    [self.contentView addSubview:self.backView];
//    self.backView.alpha = 0;
    self.picImageView.userInteractionEnabled = YES;
    self.playButton = [BaseButton buttonWithType:UIButtonTypeCustom];
    [self.picImageView addSubview:self.playButton];
  
  
    
    self.titleLabel = [[BaseLabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    
    self.relayButton = [BaseButton buttonWithType:UIButtonTypeSystem];
    [self.contentView addSubview:self.relayButton];
    [self.relayButton setTitleColor:[UIColor colorWithRed:151 / 255.0 green:151 / 255.0 blue:151 / 255.0 alpha:1] forState:UIControlStateNormal];
    
    self.commentButton = [BaseButton buttonWithType:UIButtonTypeSystem];
    [self.contentView addSubview:self.commentButton];
    [self.commentButton setTitleColor:[UIColor colorWithRed:151 / 255.0 green:151 / 255.0 blue:151 / 255.0 alpha:1] forState:UIControlStateNormal];
    
    self.favoriteButton = [BaseButton buttonWithType:UIButtonTypeSystem];
    [self.contentView addSubview:self.favoriteButton];
    [self.favoriteButton setTitleColor:[UIColor colorWithRed:151 / 255.0 green:151 / 255.0 blue:151 / 255.0 alpha:1] forState:UIControlStateNormal];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
//    self.backView.frame = CGRectMake(0, 10, SCREEN_WIDTH, 300);
    self.picImageView.frame = CGRectMake(0, 10, SCREEN_WIDTH, SCREEN_WIDTH * 360 / 640);
    self.picImageView.tag = 1000;
    self.playButton.frame = CGRectMake(SCREEN_WIDTH / 2 - 30, 100, 60, 60);
    self.playButton.layer.masksToBounds = YES;
    self.playButton.layer.cornerRadius = 30;
    [self.playButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
    [self.playButton addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];

    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.picImageView);
    }];
    
    self.titleLabel.frame = CGRectMake(10, self.picImageView.frame.size.height + 20, SCREEN_WIDTH - 20, 100);
    self.relayButton.frame = CGRectMake(0, self.picImageView.frame.size.height + 20 +self.titleLabel.frame.size.height , SCREEN_WIDTH / 3, 20);
    [self.relayButton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
    self.commentButton.frame = CGRectMake(SCREEN_WIDTH / 3 , self.picImageView.frame.size.height + 20 +self.titleLabel.frame.size.height, SCREEN_WIDTH / 3, 20);
    self.favoriteButton.frame = CGRectMake(SCREEN_WIDTH / 3 * 2, self.picImageView.frame.size.height + 20 +self.titleLabel.frame.size.height, SCREEN_WIDTH / 3, 20);
    [self.favoriteButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)setModel:(AGLChannel *)model {
   

     self.picImageView.frame = CGRectMake(0, 10, SCREEN_WIDTH, SCREEN_WIDTH * model.h.floatValue / model.w.floatValue);
    
     [self.picImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",model.picbase,model.picm]] placeholderImage:[UIImage imageNamed:@"PlaceHolder.png"]];
     [self.favoriteButton setTitle:[NSString stringWithFormat:@"点赞 %@",model.lcnt] forState:UIControlStateNormal];

  
}

- (void)click:(BaseButton *)sender {
    if (self.favoriteBlock) {
        self.favoriteBlock(sender);
    }
}



- (void)play:(BaseButton *)sender {
        if (self.playBlock) {
            self.playBlock(sender);
            
        }
}

- (void)share:(BaseButton *)sender {
    if (self.shareBlock) {
        self.shareBlock(sender);
    }

}
@end
